<%@ page contentType="text/html;charset=UTF-8" language="java" pageEncoding="UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<html>
<head>
  <meta charset="UTF-8">
  <title>员工列表</title>
  <link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/css/style.css">
</head>
<body>
<div class="container">
  <jsp:include page="/header.jsp" />
  <h2>员工列表</h2>

  <form action="${pageContext.request.contextPath}/EmployeeServlet" method="get" class="search-form">
    <input type="hidden" name="action" value="list">
    员工姓名: <input type="text" name="searchName" value="<c:out value='${searchNameVal}'/>">
    <input type="submit" value="查询">
    <a href="${pageContext.request.contextPath}/EmployeeServlet?action=list" class="button-link">显示全部</a>
  </form>

  <p><a href="${pageContext.request.contextPath}/EmployeeServlet?action=new">添加新员工</a></p>
  <table>
    <tr><th>ID</th><th>姓名</th><th>邮箱</th><th>职位</th><th>部门</th><th>入职日期</th><th>操作</th></tr>
    <c:forEach var="emp" items="${listEmployee}">
      <tr>
        <td>${emp.id}</td>
        <td><c:out value="${emp.name}"/></td>
        <td><c:out value="${emp.email}"/></td>
        <td><c:out value="${emp.position}"/></td>
        <td><c:out value="${emp.deptName}"/></td>
        <td><fmt:formatDate value="${emp.hireDate}" pattern="yyyy-MM-dd"/></td>
        <td>
          <a href="${pageContext.request.contextPath}/EmployeeServlet?action=edit&id=${emp.id}">编辑</a> |
          <a href="${pageContext.request.contextPath}/EmployeeServlet?action=delete&id=${emp.id}&searchName=<c:out value='${searchNameVal}'/>"
             onclick="return confirm('确定删除 ${emp.name} 吗？');">删除</a>
        </td>
      </tr>
    </c:forEach>
    <c:if test="${empty listEmployee}">
      <tr><td colspan="7">没有找到相关员工。</td></tr>
    </c:if>
  </table>
</div>
</body>
</html>
